<script src="/Public/js/jweixin-1.0.0.js"></script>
<script>

    $(".share_success .close").on("click", function () {

        $(".share_success").fadeOut(function () {
            $(".share_success").hide();
        });
    });
    var shareSuccess = function () {
        checkGuanZhu(function (flag) {
            if (!flag) {
                $(".share_success").fadeIn();
            }
        })
    }

    var shareData = {
        title: "<%= share.title %>",
        link: "<%- share.link %>",
        imgUrl: "<%= share.img %>",
        desc: "<%= share.desc %>",
        success: shareSuccess
    }

    var qshareData = {
        title: "<%= share.qtitle %>",
        link: "<%- share.link %>",
        imgUrl: "<%= share.img %>",
        success: shareSuccess
    }

    var jsApiList = [];
    <% for(var i = 0; i < wxconfig.jsApiList.length; i++){ %>
    jsApiList.push("<%= wxconfig.jsApiList[i] %>");
    <% } %>
    wx.config({
        debug: "<%= wxconfig.debug %>" == "true",
        appId: "<%= wxconfig.appId %>",
        timestamp: "<%= wxconfig.timestamp %>",
        nonceStr: "<%= wxconfig.nonceStr %>",
        signature: "<%= wxconfig.signature %>",
        jsApiList: jsApiList
    });
    wx.ready(function () {
        wx.onMenuShareTimeline(qshareData);
        wx.onMenuShareAppMessage(shareData);
    });

    var checkGuanZhu = function (cb) {
        $.ajax({
            url: "/index/pumpUp/checkGuanZhu",
            type: "POST",
            data: {},
            dataType: "json",
            success: function (data) {
                if (data.errno) {
                    cb && cb(false)
                } else {
                    cb && cb(true);
                }
            },
            error: function () {
                alert("网络错误");
            }
        })
    }
</script>